#!/bin/sh
# 
# Copyright © 2014-2015, Peter Harpending. <pharpend2@gmail.com>
# 
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice and this
# notice are preserved.  This file is offered as-is, without any warranty.

clean_and_die() {
  cd $orig_dir
  rm -rf tmp
  exit $1
}

orig_dir=$(pwd)
mkdir tmp

cp -rvf lysa.ltx appendices/* chapters/* bibliographies/* images/* tmp/
cd tmp

pdflatex lysa.ltx || clean_and_die 1
bibtex lysa
pdflatex lysa.ltx && pdflatex lysa.ltx

cp lysa.pdf ..
clean_and_die 0
